package com.nifostasky.comic.business.controller;

import com.nifostasky.comic.entitys.*;
import com.nifostasky.comic.query.CoHomepageInfoQuery;
import com.nifostasky.comic.query.CoSpiderInfoQuery;
import com.nifostasky.comic.service.*;
import com.nifostasky.comic.vos.CoSpiderDetailedInfoVO;
import com.nifostasky.comic.vos.JsonResult;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mainPageController")
@Api(tags = "主页")
@Slf4j
@ApiSort(9999)
@AllArgsConstructor
public class MainPageController {
    //轮播图,收藏漫画统计信息表
    private CoOtherPictureService coOtherPictureService;
    //用户收藏漫画信息表
    private CoCollectInfoService coCollectInfoService;
    //python文件信息表
    private CoSpiderInfoService coSpiderInfoService;
    //主页信息表 推荐漫画 , 最新漫画信息
    private CoHomepageInfoService coHomepageInfoService;
    //历史记录
    private CoHistoryRecordService coHistoryRecordService;

    /**
     *  获取轮播图
     */
    @ApiOperation("获取轮播图")
    @GetMapping("/queryRotationPicture")
    @ApiOperationSupport(order = 1)
    public JsonResult queryRotationPicture(){
        return new JsonResult(coOtherPictureService.queryRotationPicture());
    }

    /**
     * 获取本站推荐漫画
     */
    @ApiOperation("获取本站推荐漫画")
    @GetMapping("/queryCollectComicPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 2)
    public JsonResult queryCollectComicPage(Integer pageIndex, Integer pageSize){
        return new JsonResult(coOtherPictureService.queryCollectComicPage(pageIndex,pageSize));
    }

    /**
     * 获取用户收藏的漫画列表 分页
     */
    @ApiOperation("获取用户收藏的漫画列表 分页")
    @GetMapping("/coCollectInfoPageByUser")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 3)
    public JsonResult coCollectInfoPageByUser(Integer pageIndex,Integer pageSize,Long userId){
        return new JsonResult(coCollectInfoService.coCollectInfoPageByUser(pageIndex,pageSize,userId));
    }

    /**
     * 获取用户收藏的漫画列表 不分页
     */
    @ApiOperation("获取用户收藏的漫画列表 不分页")
    @GetMapping("/coCollectInfoListByUser")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 4)
    public JsonResult coCollectInfoListByUser(Long userId){
        return new JsonResult(coCollectInfoService.coCollectInfoListByUser(userId));
    }

    /**
     * 获取已爬取漫画列表,分页
     */
    @ApiOperation("获取已爬取漫画列表,分页")
    @GetMapping("/queryCoSpiderInfoPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 5)
    public JsonResult queryCoSpiderInfoPage(Integer pageIndex, Integer pageSize, CoSpiderInfoQuery query){
        return new JsonResult(coSpiderInfoService.queryCoSpiderInfoPage(pageIndex,pageSize,query));
    }

    /**
     * 获取已爬取漫画列表不分页
     */
    @ApiOperation("获取已爬取漫画列表不分页")
    @GetMapping("/queryCoSpiderInfoList")
    @ApiOperationSupport(order = 6)
    public JsonResult queryCoSpiderInfoList(CoSpiderInfoQuery query){
        return new JsonResult(coSpiderInfoService.queryCoSpiderInfoList(query));
    }

    /**
     * 获取最新漫画 或 推荐漫画
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @ApiOperation("获取最新漫画 或 推荐漫画")
    @GetMapping("/queryHomepageInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 7)
    public JsonResult queryHomepageInfo(Integer pageIndex, Integer pageSize, CoHomepageInfoQuery query){
        return new JsonResult(coHomepageInfoService.queryHomepageInfo(pageIndex,pageSize,query));
    }

    /**
     * 获取某用户的 历史记录
     */
    @ApiOperation("获取某用户的 历史记录")
    @GetMapping("/queryHistoryRecordPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Int", required = true),
            @ApiImplicitParam(name = "userId", value = "用户id", dataType = "Int", required = true)
    })
    @ApiOperationSupport(order = 8)
    public JsonResult queryHistoryRecordPage(Integer pageIndex,Integer pageSize,Long userId){
        return new JsonResult(coHistoryRecordService.queryHistoryRecordPage(pageIndex,pageSize,userId));
    }

    /**
     *  根据id获取py文件
     */
    @ApiOperation("根据id获取py文件")
    @GetMapping("/queryCoSpiderInfoById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "页数", dataType = "Int", required = true),
    })
    @ApiOperationSupport(order = 9)
    public JsonResult queryCoSpiderInfoById(Long id){
        return new JsonResult(coSpiderInfoService.getById(id));
    }

    /**
     * 获取用户主页默认源,如果用户有设置默认源,则使用用户默认源,否则显示系统推荐源
     */
    @ApiOperation("获取用户主页默认源")
    @GetMapping("/queryDefaultSpiderInfo")
    @ApiOperationSupport(order = 10)
    public JsonResult queryDefaultSpiderInfo(){
        return new JsonResult(coSpiderInfoService.queryDefaultSpiderInfo());
    }
}
